/*
 * c7_review8.cpp
 *
 *  Created on: Sep 1, 2013
 *      Author: cyper.yin
 */
#include <iostream>
using namespace std;
int replace(char * str, char c1, char c2);

int main_c7r8(int argc, char **argv) {
	char str[] = "hello, world";
	int count = replace(str,'o','a');
	cout << "count="  << count << endl;
	cout << "new str="  << str << endl;

	return 0;
}

int replace(char * str, char c1, char c2){
	int count = 0;
	int i = 0;
	while(*str){
		if(*str == c1){
			*str = c2;
			count++;
		}
		str++;
		i++;
	}

	//reset pointer.
	str = str - i;

	return count;
}

